package conveter;
import java.lang.reflect.Member;
import java.util.Map;
import ognl.DefaultTypeConverter;
import entity.User;

/**
 * @author dingyuanwei
 * @version 建立時間：Dec 23, 20102:31:01 PM
 * 類別說明:
 */
public class UserConverter extends DefaultTypeConverter {

	@Override
	public Object convertValue(Map context, Object arg1, Member arg2, String arg3, Object value, Class toType) {
		if(toType == User.class){
			String[] params = (String[])value;
			User user = new User();
			String[] userValues = params[0].split(",");
			user.setUserName(userValues[0]);
			user.setUserPassword(userValues[1]);
			return user;
		}else if(toType == String.class){
			User user = (User)value;
			return "<"+user.getUserName()+","+user.getUserPassword()+">";
			
		}
		return null;
	}

}
